package com.central.common.feign;

import com.central.common.constant.ServiceNameConstants;
import com.central.common.feign.fallback.UserServiceFallbackFactory;
import com.central.common.model.LoginAppUser;
import com.central.common.model.PageResult;
import com.central.common.model.SysUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author td
 */
@FeignClient(name = ServiceNameConstants.USER_SERVICE, fallbackFactory = UserServiceFallbackFactory.class, decode404 = true)
public interface UserService {
    /**
     * feign rpc访问远程/users/{username}接口
     * 查询用户实体对象SysUser
     *
     * @param username
     * @return
     */
    @GetMapping(value = "/users/name/{username}")
    SysUser selectByUsername(@PathVariable("username") String username);

    /**
     * feign rpc访问远程/users-anon/login接口
     *
     * @param username
     * @return
     */
    @GetMapping(value = "/users-anon/login", params = "username")
    LoginAppUser findByUsername(@RequestParam("username") String username);

    /**
     * 通过手机号查询用户、角色信息
     *
     * @param mobile 手机号
     */
    @GetMapping(value = "/users-anon/mobile", params = "mobile")
    LoginAppUser findByMobile(@RequestParam("mobile") String mobile);

    /**
     * 根据OpenId查询用户信息
     *
     * @param openId openId
     */
    @GetMapping(value = "/users-anon/openId", params = "openId")
    LoginAppUser findByOpenId(@RequestParam("openId") String openId);

    /**
     * 根据用户id查询用户实体
     * @param userId
     * @return
     */
    @GetMapping(value = "/users/{userId}")
    SysUser selectById(@PathVariable("userId") Long userId);

    /**
     * 项目用户查询列表
     * @param page
     * @param limit
     * @param proId
     * @return
     */
    @GetMapping("/users/findUsersOnPro")
    PageResult<SysUser> findUsersOnPro(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("proId") Long proId);

    /**
     * 项目用户字典
     * @param proId
     * @return
     */
    @GetMapping("/users/findUserMapOnPro/{proId}")
    Map<String, SysUser> findUserMapOnPro(@PathVariable("proId") Long proId);

}
